package com.luoxiang.socialandroid.adapter;

import static com.luoxiang.lib_common.common.Constants.MmkvConst.DOMAIN;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.luoxiang.socialandroid.R;
import com.luoxiang.socialandroid.app.MyAppliaction;
import com.luoxiang.socialandroid.bean.Gift1;

import java.util.List;

public class GiftsAdapter extends RecyclerView.Adapter<GiftsAdapter.ViewHolder> {
    private List<Gift1> list;

    public GiftsAdapter(List<Gift1> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public GiftsAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_receivegifts, parent, false);
        GiftsAdapter.ViewHolder holder = new GiftsAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull GiftsAdapter.ViewHolder holder, int position) {
        if (list != null) {
            if (list.get(position) != null) {
                Glide.with(MyAppliaction.getContext())
                        .load(DOMAIN + list.get(position).getIcon())
                        .into(holder.img_giftimg);
                holder.tv_receivegift.setText(list.get(position).getName());
                holder.tv_countgift.setText("x" + list.get(position).getNum());
            }
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView img_giftimg;
        TextView tv_receivegift, tv_countgift;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            img_giftimg = itemView.findViewById(R.id.img_giftimg);
            tv_receivegift = itemView.findViewById(R.id.tv_receivegift);
            tv_countgift = itemView.findViewById(R.id.tv_countgift);
        }
    }
}
